﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Data.SqlClient;


namespace BookStore.Data
{
    public class catogoryController
    {

        static SqlConnection con = sqlDataProvider.getConnect();
        static DataTable dt;
        public static DataTable Get_catalogALL()
        {
            using (SqlDataAdapter da = new SqlDataAdapter("[Get_catALL]", con))
            {
                da.SelectCommand.CommandType = CommandType.StoredProcedure;
                dt = new DataTable();
                da.Fill(dt);
            }
            return dt;
        }
        public static DataTable Get_catalogID(int id)
        {
            using (SqlCommand cmd = new SqlCommand("[Get_catid]", con))
            {
                cmd.CommandType = CommandType.StoredProcedure;
                cmd.Parameters.Add(new SqlParameter("@catogoryID", id));
                SqlDataAdapter da = new SqlDataAdapter(cmd);

                dt = new DataTable();
                da.Fill(dt);
            }
            return dt;
        }
        #region getbyID

        public static DataTable getbyid(int catogoryID)
        {
            return dt;
        }

        public static catogoryInfo getbyID(int catogoryID)

        {
            catogoryInfo objCatogory = new catogoryInfo();
            using (SqlCommand cmd = new SqlCommand("getIDCatogory", con))
            {
                cmd.CommandType = CommandType.StoredProcedure;
                cmd.Parameters.Add(new SqlParameter("@catogoryID", catogoryID));

                SqlDataAdapter data = new SqlDataAdapter(cmd);
                dt = new DataTable();
                data.Fill(dt);

                SqlDataReader dr = cmd.ExecuteReader();
                if (dr.HasRows)
                {
                    while (dr.Read())
                    {
                        objCatogory.catogoryID = dr.GetInt32(0);
                        objCatogory.catogoryName = dr.GetString(1);
                    }
                }
                dr.Close();

            }
            return objCatogory;
        }
     
        #endregion

        #region getbyAll
        public static DataTable ListCatogory()
        {
            using (SqlDataAdapter da = new SqlDataAdapter("select * from dbo.tblCatogory", con))
            {
               // da.SelectCommand.CommandType = CommandType.StoredProcedure;
                dt = new DataTable();
                da.Fill(dt);
            }
            return dt;
        }
        #endregion

        #region insert
        public static bool insertCatogory(catogoryInfo objCatogory)
        {
            using (SqlCommand cmd = new SqlCommand("insertCatogory", con))
            {
                cmd.CommandType = CommandType.StoredProcedure;
                //cmd.Parameters.Add(new SqlParameter("@catogoryID", objCatogory.catogoryID));
                cmd.Parameters.Add(new SqlParameter("@catogryName", objCatogory.catogoryName));
                cmd.ExecuteNonQuery();
            }
            return true;
        }
        #endregion

        #region update
        public static bool updateCatogory(catogoryInfo objCatogory)
        {
            using (SqlCommand cmd = new SqlCommand("updateCatogory", con))
            {
                cmd.CommandType = CommandType.StoredProcedure;
                cmd.Parameters.Add(new SqlParameter("@catogoryID", objCatogory.catogoryID));
                cmd.Parameters.Add(new SqlParameter("@catogryName", objCatogory.catogoryName));
                cmd.ExecuteNonQuery();
            }
            return true;
        }
        #endregion

        #region delete
        public static bool deleteCatogory(int catogoryID)
        {
            using (SqlCommand cmd = new SqlCommand("deleteCatogory", con))
            {
                cmd.CommandType = CommandType.StoredProcedure;
                cmd.Parameters.Add(new SqlParameter("@catogoryID", catogoryID));
                cmd.ExecuteNonQuery();
            }
            return true;
        }
        #endregion


      
        public static bool checkExist(int catogoryID){
            
            using (SqlCommand cmd = new SqlCommand("checkExist", con))
            {
                return true;
            }
            }

       
        public static bool checkCatogoryID(int catogoryID)
        {
            SqlCommand cmd = new SqlCommand("checkCatogoryID", con);
            cmd.CommandType = CommandType.StoredProcedure;
            cmd.Parameters.Add(new SqlParameter("@catogoryID", catogoryID));
            SqlDataReader dr = cmd.ExecuteReader();
            if (dr.HasRows)

            {
                return true;
            }
            dr.Close();
            return false;
        }
       
    }
}
